using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Listener<C, E> {
	
	private Dictionary<C, List<System.Action<E>>> listeners = new Dictionary<C, List<System.Action<E>>>();
	
	// Add a listener on a specific channel.
	public virtual void add(C channel, System.Action<E> listener) {
		if (!listeners.ContainsKey(channel)) {
			listeners.Add(channel, new List<System.Action<E>>());
		}
		
		listeners[channel].Add(listener);
	}
	
	// Notify listeners on a specific channel.
	public virtual void notify(C channel, E ev) {
		if (listeners.ContainsKey(channel)) {
			foreach (System.Action<E> listener in listeners[channel]) {
				listener(ev);
			}
		}
	}
}